package com.sunyard.client2;

import com.sunyard.client.SunEcmClientApi;
import com.sunyard.client.impl.SunEcmClientHttpApiImpl;
import com.sunyard.client.impl.SunEcmClientSocketApiImpl;
import com.sunyard.client.impl.SunEcmClientWebserviceApiImpl;
import com.sunyard.client2.conf.ConfUtil;

public class ConnectionFactory {
	public static SunEcmClientApi getConnection() {
		String type = ConfUtil.getString("connectionType", "");
		if (type.equals("Socket")) {
			boolean b = ConfUtil.getBoolean("socketSSL", false);
			int port = 0;
			if (b) {
				port = ConfUtil.getInt("socketSSLPort", 8025);
			} else {
				port = ConfUtil.getInt("socketPort", 8023);
			}
			return new SunEcmClientSocketApiImpl(ConfUtil.getString("ip", "localhost"), port, b);
		} else if (type.equals("Http")) {
			return new SunEcmClientHttpApiImpl(ConfUtil.getString("ip", "localhost"),
					ConfUtil.getInt("httpPort", 8080), ConfUtil.getString("serverName", "SunECMDM"));
		} else if (type.equals("WebService")) {
			return new SunEcmClientWebserviceApiImpl(ConfUtil.getString("ip", "localhost"), ConfUtil.getInt("httpPort",
					8080), ConfUtil.getString("serverName", "SunECMDM"));
		} else {
			throw new RuntimeException("错误的连接类型：" + type);
		}
	}
}
